<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <textarea name="" id="" cols="30" rows="10" v-model="val"></textarea>
        <button @click="publish">发表</button>
        <ul>
            <!-- 显示评论的地方 -->
            <li v-for='(item, index) in valArr'>{{item.name}}  {{item.content}}  {{item.time}} {{item.num}}   
                <button @click="totalizer(item)">点赞</button>
                <button @click="top(item)">置顶</button>
                <button @click="del(index)">删除</button>
            </li>
        </ul>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
        Vue.config.productionTip = false;

        let vm = new Vue({
            el:"#app",
            data:{
                val:"",
                valArr:[
                    {
                        name:"xxx",
                        content:'xxxx',
                        time:'9月1日',
                        num:0
                    }
                ],
            },
            methods: {
                publish() {
                    this.valArr.push({
                        name:"xxx",
                        content:this.val,
                        time:'9月1日',
                        num:0
                    });
                    this.val = ""
                },
                totalizer(item) {
                    item.num++
                },
                del(index) {
                    this.valArr.splice(index, 1)
                },
                top(item) {
                    this.valArr.splice(this.valArr.indexOf(item), 1);
                    this.valArr.unshift(item);
                }   
            },
        })
    </script>
</body>
</html>